package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.RequestAndResultCode;
import com.bjesc_b2c.app.appraiset.adapter.MoreCheckAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.utils.DataUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import master_bean.CarForBean;

/**
 * Created by yidong on 2017/8/19.
 */

public class MoreCheckActivity extends BaseActivity {
    @Bind(R.id.recycler_carfrom)
    RecyclerView recyclerView;
    @Bind(R.id.tv_title)

    TextView title;
    private List<CarForBean> typeList;
    private LinearLayoutManager manager;
    private MoreCheckAdapter adapter;
    private int sType;
    private Intent mintent = new Intent();
    private ArrayList<String> typeIdList = new ArrayList<>();
    @Override
    protected int getLayout() {
        return R.layout.activity_more_check;
    }

    @Override
    protected void initEventAndData() {
        sType = getIntent().getIntExtra("SelecType", 1);
        if (sType == 1) {
            title.setText("价格选择");
            typeList = DataUtils.getMorePriceList(this);
        } else if (sType == 2) {
            title.setText("车辆类型");
            typeList = DataUtils.getCarTypeList(this);
        }else if(sType == 3){
            title.setText("车龄");
            typeList = DataUtils.getCarAgeList(this);
        }
        adapter = new MoreCheckAdapter(this,R.layout.list_item_produk,typeList);
        manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
//      adapter.setOnItemClickListener(this);
    }

    @Override
    protected void createPresenter() {

    }

    @OnClick({R.id.iv_return,R.id.tv_sure})
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_return:
                finish();
                break;
            case R.id.tv_sure:
//                mintent.putExtra("CheckList",(Serializable) adapter.checkList);
                String name = "";
                for (int i = 0;i < adapter.checkList.size(); i++){
                    typeIdList.add(adapter.checkList.get(i).getId());
                    if (i ==0) {
                        name += adapter.checkList.get(i).getName();
                    }else{
                        name += "/"+adapter.checkList.get(i).getName();
                    }
                }
                mintent.putExtra("Name",name);
                mintent.putStringArrayListExtra("typeIdList",typeIdList);
                if (sType == 1) {
                    setResult(RequestAndResultCode.CarrosserieDescribe_Back_rearApronBar, mintent);//价格
                    finish();
                }
                if (sType == 2) {
                    setResult(RequestAndResultCode.CarrosserieDescribe_Back_spareBar, mintent);//类型
                    finish();
                }
                if (sType == 3) {
                    setResult(RequestAndResultCode.CarrosserieDescribe_Back_rightRearInnerPlate, mintent);//
                    finish();
                }
//                for (int i = 0;i <adapter.checkList.size();i++){
//                   Logger.d(adapter.checkList.get(i).getName());
//               }
                break;
        }

    }

}
